import { getOrderStatus } from "@/api/modules/transactionManagement";
import { Space, Tag } from "antd";
import { keys, map, join, sumBy, isEmpty } from "lodash";
import styles from "./index.module.less";
import { getCategoryList, getModalityList } from "@/api/modules/course";
import { Link } from "react-router-dom";

export const COURSE_STATUS = {
	//下架
	down: -1,
	//上架
	up: 1,
	//待上架
	waitUp: 0
};

export const CODE_STATUS = {
	all: "",
	unUsed: "UNUSED",
	using: "USING",
	used: "USED",
	expired: "EXPIRED"
};

export const formList = [
	{
		label: "全部",
		key: CODE_STATUS.all
	},
	{
		label: "未使用",
		key: CODE_STATUS.unUsed
	},
	{
		label: "使用中",
		key: CODE_STATUS.using
	},
	{
		label: "已使用",
		key: CODE_STATUS.used
	},
	{
		label: "已过期",
		key: CODE_STATUS.expired
	}
];

export const getSearchOptions = (info: string) => {
	return [
		{
			type: "input",
			placeholder: "优惠ID",
			name: "code"
		},

		{
			type: "select",
			placeholder: "使用状态",
			name: "type",
			options: formList
		}
	];
};

export enum SECOND_TAB_VALUES {
	//全部
	all = "all",
	//满减
	fullCut = "fixed_amount",
	//折扣
	percentCut = "percentage"
}

export const TABS = [
	{
		label: "优惠券",
		key: "discount"
	}
];

export const SECOND_OPTIONS = [
	{
		label: "全部",
		key: SECOND_TAB_VALUES.all
	},
	{
		label: "满减券",
		key: SECOND_TAB_VALUES.fullCut
	},
	{
		label: "折扣券",
		key: SECOND_TAB_VALUES.percentCut
	}
]

export const getTableColumns = ({ }) => [
	{
		title: "数量",
		dataIndex: "course_name",
		width: 140,
		align: "left",
		className: styles.shop
	},
	{
		title: "优惠码ID",
		dataIndex: "code",
		width: 140,
		ellipsis: true
	},
	{
		title: "优惠类型",
		dataIndex: "type",
		width: 140,
		renderText: (v: any) => {
			return SECOND_OPTIONS?.find(i => i?.key == v)?.label ?? "-";
		}
	},
	{
		title: "使用范围",
		dataIndex: "course_menus_id",
		width: 140
	},
	{
		title: "有效期",
		dataIndex: "end_time",
		width: 160,
		ellipsis: true,
		render: (_: any, record: any) => {
			return (
				<>
					<p>{`起：${record.start_time}`}</p>
					<p>{`止：${record.end_time}`}</p>
				</>
			);
		}
	},
	{
		title: "使用次数",
		dataIndex: "max_uses",
		width: 200,
		render: (_: any, record: any) => {
			return `${record.have_used}/${record.max_uses}`;
		}
	},
	{
		title: "状态",
		dataIndex: "course_status",
		width: 160,
		render: (_, record) => {
			const value = record?.course_status;
			const bgColor = value === COURSE_STATUS.up ? "#E5FDE9" : "#FFF8ED";
			const color = value === COURSE_STATUS.up ? "#0B801E" : "#DE6700";
			return (
				<Tag style={{ background: bgColor, color, border: "none", marginRight: 0 }}>
					{value === COURSE_STATUS.up
						? "运营中"
						: value === COURSE_STATUS.down
						? "已下架"
						: value === COURSE_STATUS.waitUp
						? "待上架"
						: "-"}
				</Tag>
			);
		}
	}
];
